/// @tags: DivGraph Hall
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

namespace BlueQuantum {

int const M = 7;

int n, m;
int cnt[M][M], num[M], exp[M], vis[M];
vector<pair<int, int> > ans;

inline bool check() {
  for (int S = 1; S < (1 << m) - 1; ++S) {
    int cnta = 0, cntb = 0;
    for (int i = 1; i <= m; ++i)
      if (S >> (i - 1) & 1) cnta += num[i];
    for (int i = 1; i <= m; ++i)
      for (int j = i; j <= m; ++j)
        if ((S >> (i - 1) & 1) | (S >> (j - 1) & 1)) cntb += cnt[i][j];
    if (cnta > cntb) return false;
  }
  return true;
}

inline int main() {
  cin >> n;
  int t = n;
  while (t) t /= 10, m += 1;
  exp[1] = 1;
  for (int i = 2; i <= m; ++i) exp[i] = exp[i - 1] * 10;
  for (int i = 1; i < m; ++i) num[i] = exp[i + 1] - exp[i];
  num[m] = n - exp[m] + 1;
  char a[M], b[M];
  for (int i = 1; i < n; ++i) {
    cin >> a >> b;
    int u = strlen(a), v = strlen(b);
    cnt[u][v] += 1;
    if (u != v) cnt[v][u] += 1;
  }
  if (check() == false) {
    cout << "-1";
    return 0;
  }
  int n_cnt = 0;
  vis[1] = 1;
  exp[1] += 1;
  num[1] -= 1;
  while (n_cnt < n - 1) {
    for (int i = 1; i <= m; ++i) {
      if (vis[i] == true) {
        for (int j = 1; j <= m; ++j) {
          if (!cnt[i][j] || !num[j]) continue;
          cnt[i][j] -= 1;
          num[j] -= 1;
          if (i != j) cnt[j][i] -= 1;
          if (check()) {
            ans.push_back(make_pair(exp[i] - 1, exp[j]));
            exp[j] += 1;
            vis[j] = 1;
            n_cnt += 1;
          } else {
            cnt[i][j] += 1;
            num[j] += 1;
            if (i != j) cnt[j][i] += 1;
          }
        }
      }
    }
  }
  for (vector<pair<int, int> >::iterator i = ans.begin(), ilim = ans.end(); i != ilim;
       ++i)
    cout << i->first << ' ' << i->second << '\n';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF611H New Year and Forgotten Tree.in", "r", stdin);
  freopen("CF611H New Year and Forgotten Tree.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
